﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model;

namespace DAL
{
    public class ProductType_Flow : BaseRepository<ProductType_FlowInfo>, IProductType_Flow
    {
        #region 静态变量部分
        private const string PARM_FLOW_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_FLOW_ASSEMBLESTEP = "@AssembleStep";
        private const string PARM_FLOW_JOINTINGSTEP = "@JointingStep";
        private const string PARM_FLOW_AGINGSTEP = "@AgingStep";
        private const string PARM_FLOW_DEBUGATESTEP = "@DebugATEStep";
        private const string PARM_FLOW_DEBUGSTEP = "@DebugStep";
        private const string PARM_FLOW_QCFIXEDSTEP = "@QCFixedStep";
        private const string PARM_FLOW_PIMSTEP = "@PIMStep";
        private const string PARM_FLOW_POWERSTEP = "@PowerStep";
        private const string PARM_FLOW_DEBUGACTIVEATESTEP = "@DebugActiveATEStep";
        private const string PARM_FLOW_VOLTAGECHECKSTEP = "@VoltageCheckStep";
        private const string PARM_FLOW_CURRENTCHECKSTEP = "@CurrentCheckStep";
        private const string PARM_FLOW_SENSITIVITYSTEP = "@SensitivityStep";
        private const string PARM_FLOW_ATESTEP = "@ATEStep";
        private const string PARM_FLOW_ACTIVEATESTEP = "@ActiveATEStep";
        private const string PARM_FLOW_OIP3STEP = "@OIP3Step";
        private const string PARM_FLOW_HFATESTEP = "@HFATEStep";
        private const string PARM_FLOW_AIRTIGHTNESSSTEP = "@AirtightnessStep";
        private const string PARM_FLOW_PIMSECONDSTEP = "@PIMSecondStep";
        private const string PARM_FLOW_PACKCHECKSTEP = "@PackCheckStep";
        private const string PARM_FLOW_PACKAGESTEP = "@PackageStep";

        private const string PARM_FLOW_PRODUCTSN = "@ProductSN";
        private const string PARM_FLOW_STEPITEM = "@StepItem";
        private const string PARM_FLOW_RESULT = "@result";
        #endregion

        #region 数据检索部分
        public IList<ProductType_FlowInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("ProductType_Flow_select");
        }

        public ProductType_FlowInfo LoadEntity<T1>(T1 id)
        {
            SqlParameter parm = GetParameter();
            parm.Value = id;
            return ExcuteSqlToGetEntity("ProductType_Flow_selectbyID", parm);
        }
        #endregion

        #region 流程控制部分
        public bool ProductType_Flow_HasValidSevenStep(string productSN, string productTypeID,string stepItem)
        {
            SqlParameter[] testParms = GetStepParameters();
            testParms[0].Value = productSN;
            testParms[1].Value = productTypeID;
            testParms[2].Value = stepItem;
            testParms[3].Direction = ParameterDirection.Output;

            bool isvalid = (bool)sqlHelper.ExecuteScalar(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "ProductType_Flow_HasValidPostStep", testParms);
            //bool isvalid = (bool)testParms[3].Value;
            return isvalid;
        }
        
        #endregion

        #region 参数部分
        private static SqlParameter[] GetStepParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_FLOW_PRODUCTSN,SqlDbType.NVarChar,50),
					new SqlParameter(PARM_FLOW_PRODUCTTYPEID,SqlDbType.NVarChar,50),
                    new SqlParameter(PARM_FLOW_STEPITEM,SqlDbType.NVarChar,50),
					new SqlParameter(PARM_FLOW_RESULT,SqlDbType.Bit,1)
                };
            return parms;
        }
        #endregion

        #region 重写基类部分
        public override ProductType_FlowInfo GetEntityRecord(SqlDataReader rdr)
        {
            ProductType_FlowInfo pro = new ProductType_FlowInfo
            {
                ProductTypeID = rdr.GetValue(0).ToString(),
                ProductTypeName = rdr.GetValue(1).ToString(),
                AssembleStep = rdr.GetBoolean(2),
                JointingStep = rdr.GetBoolean(3),
                AgingStep = rdr.GetBoolean(4),
                DebugATEStep = rdr.GetBoolean(5),
                DebugStep = rdr.GetBoolean(6),
                QCFixedStep = rdr.GetBoolean(7),
                PIMStep = rdr.GetBoolean(8),
                PowerStep = rdr.GetBoolean(9),
                DebugActiveATEStep = rdr.GetBoolean(10),
                VoltageCheckStep = rdr.GetBoolean(11),
                CurrentCheckStep = rdr.GetBoolean(12),
                SensitivityStep = rdr.GetBoolean(13),
                ATEStep = rdr.GetBoolean(14),
                ActiveATEStep = rdr.GetBoolean(15),
                OIP3Step = rdr.GetBoolean(16),
                HFATEStep = rdr.GetBoolean(17),
                AirtightnessStep = rdr.GetBoolean(18),
                PIMSecondStep = rdr.GetBoolean(19),
                PackCheckStep = rdr.GetBoolean(20),
                PackageStep = rdr.GetBoolean(21),
            };
            return pro;
        }

        public override ProductType_FlowInfo GetEntityRecord()
        {
            ProductType_FlowInfo pro = new ProductType_FlowInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return null;
        }

        public override string GetUpdatesp()
        {
            return "ProductType_Flow_Update";
        }

        public override string GetDeletesp()
        {
            return null;
        }


        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_FLOW_PRODUCTTYPEID, SqlDbType.NVarChar, 50);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_FLOW_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_FLOW_ASSEMBLESTEP,SqlDbType.Bit,1),
                    new SqlParameter(PARM_FLOW_JOINTINGSTEP,SqlDbType.Bit,1),
                    new SqlParameter(PARM_FLOW_AGINGSTEP,SqlDbType.Bit,1),
                    new SqlParameter(PARM_FLOW_DEBUGATESTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_DEBUGSTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_QCFIXEDSTEP,SqlDbType.Bit,1),
                    new SqlParameter(PARM_FLOW_PIMSTEP,SqlDbType.Bit,1),
					new SqlParameter(PARM_FLOW_POWERSTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_DEBUGACTIVEATESTEP, SqlDbType.Bit, 1),
					new SqlParameter(PARM_FLOW_VOLTAGECHECKSTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_CURRENTCHECKSTEP,SqlDbType.Bit, 1),
					new SqlParameter(PARM_FLOW_SENSITIVITYSTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_ATESTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_ACTIVEATESTEP, SqlDbType.Bit, 1),
					new SqlParameter(PARM_FLOW_OIP3STEP, SqlDbType.Bit, 1),
					new SqlParameter(PARM_FLOW_HFATESTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_AIRTIGHTNESSSTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_PIMSECONDSTEP, SqlDbType.Bit, 1),
                    new SqlParameter(PARM_FLOW_PACKCHECKSTEP,SqlDbType.Bit,1),
                    new SqlParameter(PARM_FLOW_PACKAGESTEP,SqlDbType.Bit,1)
                };
            return parms;
        }

        public override void SetParameters(ProductType_FlowInfo pro, params SqlParameter[] Parms)
        {
            Parms[0].Value = pro.ProductTypeID;
            Parms[1].Value = pro.AssembleStep;
            Parms[2].Value = pro.JointingStep;
            Parms[3].Value = pro.AgingStep;
            Parms[4].Value = pro.DebugATEStep;
            Parms[5].Value = pro.DebugStep;
            Parms[6].Value = pro.QCFixedStep;
            Parms[7].Value = pro.PIMStep;
            Parms[8].Value = pro.PowerStep;
            Parms[9].Value = pro.DebugActiveATEStep;
            Parms[10].Value = pro.VoltageCheckStep;
            Parms[11].Value = pro.CurrentCheckStep;
            Parms[12].Value = pro.SensitivityStep;
            Parms[13].Value = pro.ATEStep;
            Parms[14].Value = pro.ActiveATEStep;
            Parms[15].Value = pro.OIP3Step;
            Parms[16].Value = pro.HFATEStep;
            Parms[17].Value = pro.AirtightnessStep;
            Parms[18].Value = pro.PIMSecondStep;
            Parms[19].Value = pro.PackCheckStep;
            Parms[20].Value = pro.PackageStep;
        }
        #endregion
    }
}
